//
//  UIlable+Extension.swift
//  Weibo
//
//  Created by 明丽 on 16/1/17.
//  Copyright © 2016年 明丽. All rights reserved.
//

import UIKit
extension UILabel {

//扩展一个工厂方法
    class func labelFactory(title: String,fontSize: CGFloat, color: UIColor) -> UILabel{
        let l=UILabel()
        l.font = UIFont.systemFontOfSize(fontSize)
        l.text = title
        //设置行数
        l.numberOfLines = 0
        l.textColor = color
        l.textAlignment = .Center
        l.sizeToFit()
        
        return l
        }
    //在扩展中只能够添加便利的构造函数
    convenience init(title: String,fontSize: CGFloat, color: UIColor,margin: CGFloat = 0) {
        self.init()
        font = UIFont.systemFontOfSize(fontSize)
        text = title
        numberOfLines  = 0
        textColor = color
        textAlignment = .Center
        if margin > 0 {
        
        textAlignment = .Left
            //设置最大宽度
            preferredMaxLayoutWidth = KWidth - 2 * margin

        }
        
        
        sizeToFit()
        
        
    }
    
    
}
